<template>
  <div class="slot-body">
    {{ count }}
  </div>
</template>

<script>
import { requestGet } from '@/api/system/common'
export default {
  name: 'VisitingSlot',
  props: {
    column: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      content: {}, // 配置信息
      count: 0
    }
  },
  watch: {
    column: {
      handler(newData, oldData) {
        this.content = newData
        // 只有在关联的数据项 存在，才会执行查询，否则直接返回0
        if (undefined !== this.content.sjly && undefined !== this.content.sjly.id) {
          this.initData(this.content.sjly.id)
        }
      },
      immediate: true, // 父组件第一次传值时，执行handler，false则第一次不执行
      deep: false // formType为对象时，设置为true，此属性监听对象发生变化
    }
  },
  methods: {
    initData(id) {
      requestGet('rest/api/temp/v2/column/analysis/value', { id: id })
        .then(res => {
          if (undefined !== res.data && undefined !== res.data.data && res.data.data.length > 0) {
            this.count = res.data.data[0][this.content.number]
          }
        }).catch(() => {
          this.count = 0
        })
    }
  }
}
</script>

<style scoped>
</style>
